package com.xmall.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmall.auth.dao.SysRolePermissionRelationMapper;
import com.xmall.auth.entity.SysRolePermissionRelation;
import com.xmall.auth.service.ISysRolePermissionRelationService;
import com.xmall.common.config.PlatformContant;
import com.xmall.common.config.PojoUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 后台用户角色和权限关系表 服务实现类
 * </p>
 *
 * @author liuzh
 * @since 2020-06-14
 */
@Service
public class SysRolePermissionRelationServiceImpl extends ServiceImpl<SysRolePermissionRelationMapper, SysRolePermissionRelation> implements ISysRolePermissionRelationService {
        @Autowired
        SysRolePermissionRelationMapper sysRolePermissionRelationMapper;
        @Override
        public boolean saveSysRolePermissionRelation(SysRolePermissionRelation sysRolePermissionRelation) {
        PojoUtils.setSysProperties(sysRolePermissionRelation, PlatformContant.OpType.insert);
        return save(sysRolePermissionRelation);
        }

        @Override
        public boolean updateSysRolePermissionRelation(Long id , SysRolePermissionRelation sysRolePermissionRelation) {
        SysRolePermissionRelation oldSysRolePermissionRelation = getById(id);
        BeanUtils.copyProperties(sysRolePermissionRelation, oldSysRolePermissionRelation);
        PojoUtils.setSysProperties(oldSysRolePermissionRelation, PlatformContant.OpType.update);
        boolean update = update(
        oldSysRolePermissionRelation,
        new QueryWrapper<SysRolePermissionRelation>()
        .lambda().eq(SysRolePermissionRelation::getId, id)
        );
        return update;
        }

        @Override
        public boolean deleteSysRolePermissionRelation(Long id) {
        boolean b = removeById(id);
        return b;
        }

        @Override
        public SysRolePermissionRelation getSysRolePermissionRelation(Long id) {
        SysRolePermissionRelation sysRolePermissionRelation = getById(id);
        return sysRolePermissionRelation;
        }
}
